<?php
/**
 * Created by PhpStorm.
 * User: CYJiao
 * Date: 6/18/15
 * Time: 22:26
 */

?>

<style>
    .table-patient table{border-right:1px dashed #EEEEEE;border-bottom:1px dashed #EEEEEE}
    .table-patient table td{border-left:1px dashed #EEEEEE;border-top:1px dashed #EEEEEE}
    .table-patient table th{border-left:1px dashed #EEEEEE;border-top:1px dashed #EEEEEE}
</style>

<script>
    function save(){
        if($('#true_name').val() == ''){
            alert('真实姓名不能为空');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '<?php echo CController::createUrl('patient/add') ;?>',
            data: $('#form-ehr').serialize(),
            success: function(data){
                if(data.status==0){
                    alert('保存成功！\n你可以在左侧患者列表中查看。');
                    parent.$('#patientList').datagrid('load');

                    addTab(data.true_name+"_"+data.username,'<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=patient/getPatientsMainAccordion&pk_outpatient_id='+data.patient_id,'icon-patient',1);
                    parent.$('#center-panel').tabs('close','添加患者');
                    

                    //addPatientTab('历史病历','<?php echo Yii::app()->request->baseUrl; ?>/index.php?r=eHR/getPatientEHRContent&pk_outpatient_ehr_id='+data.result,'icon-ehr');
                }else if(data.status==2){
                    alert('已经存在该患者');
                }else{
                    alert('保存失败，请联系技术人员');
                }
            },
            dataType: 'json'
        });
    }
    function get_message(){

        var re = /^1\d{10}$/;
        if (! re.test($('#phone').val())){
            alert('号码格式不对');
            return false;
        }
            
        $.ajax({
            type: 'POST',
            url: '<?php echo CController::createUrl('patient/send_message') ;?>',
            data: {phone:$('#phone').val()},
            success: function(data){
                if(data == 1){
                    alert('该手机号码已经被注册过');
                }else{
                    alert('已经发送验证码，请注意查收');
                }
            },
            dataType: 'json'
        });
        
    }
    $(document).ready(function(){
        $("#phone").keydown(function(){
            
            $('#get_message').show();
            $('#sort_message').show();
        });
    })
</script>

<div class="easyui-panel" data-options="border:false,fit:true" style="padding:5px;">
    
    
    <form id="form-ehr" method="post">
        
        
            <div title="患者信息" data-options="selected:true" style="overflow:auto;padding:10px;">
            <div class="easyui-panel" style="width:800px;padding:5px;background:#fafafa;margin-bottom: 10px;">
            <div class="table-patient easyui-layout"  data-options="fit:true">
                <table style="width:100%;" data-options="fit:true">
                    <tbody>
                    <tr>
                        <th align="right">真实姓名：</th>
                        <td><input class="easyui-textbox" name="true_name" id="true_name" required='true' value=""/></td>
                        <th align="right">性别：</th>
                            
                        <td>
                            <select class="" name="gender">
                                <option value="1">男</option>
                                <option value="2">女</option>
                               
                            </select>
                        </td>
                        <th align="right">电话：</th>
                       
                            <td><input name="phone" id="phone" style="width:120px;" value=""/>
                                <a id="get_message" style="display:none" href="javascript:void(0)" class="easyui-linkbutton" onclick="get_message();">获取验证码</a>
                                <input id="sort_message" style="display:none;width:50px;" name="sort_message" value=""/>
                            </td>
                            <td></td>
                       
                    </tr>
                    <tr>
                        <th align="right">年龄：</th>
                        <td><input class="easyui-textbox" style="width:40px;" name="age" value=""/>&nbsp;岁</td>
                        
                        <th align="right">职业：</th>
                        <td><input class="easyui-textbox" style="width:50px;" name="occupation" value=""></td>
                    </tr>
                    <tr>
                        <th align="right">住址：</th>
                        <td colspan="5"><input class="easyui-textbox" style="width:50%" name="location" value=""></td>
                    </tr>
                    <tr>
                        <th align="right">体重：</th>
                        <td><input class="easyui-textbox" style="width:50px;" name="weight" value="">&nbsp;kg</td>
                        <th align="right">身高：</th>
                        <td><input class="easyui-textbox" style="width:50px;" name="stature" value="">&nbsp;cm</td>
                        
                    </tr>
                    <tr>
                        <th align="right">饮酒：</th>
                        <td>
                            <select class="" name="alcohol">
                                <option value="1" >无</option>
                                <option value="2" >很少</option>
                                <option value="3" >有时</option>
                                <option value="4" >经常</option>
                                <option value="5" >总是</option>
                            </select>
                        </td>
                        <th align="right">吸烟：</th>
                        <td><input class="easyui-textbox" style="width:50px;" name="smoke" value=""> 支/天</td>
                        <th align="right">血型：</th>
                        <td>
                            <select class="" name="blood_type">
                                <option value="1">A</option>
                                <option value="2">B</option>
                                <option value="3">AB</option>
                                <option value="4">O</option>
                            </select>
                        </td>
                    </tr>
                   
                    </tbody>
                </table>
            </div>
            </div>
            </div>

            
            <!--<div id="ehr-tab" class="easyui-tabs" data-options="border:true,plain:true,fit:true" style="height:500px;">
            <div title="病历" data-options="iconCls:'icon-ehr'" style="padding:5px;height:500px;">
                <table cellpadding="5" style="width:100%;">
                    <tr>
                        <td style="width:100px;">过敏史：</td>
                        <td colspan="5"><input class="easyui-textbox" name="allergy" value=""></td>
                    </tr>
                    <tr>
                        <td style="width:100px;">患者主诉:</td>
                        <td><input class="easyui-textbox" type="text" name="outpatient_complaint" data-options="multiline:true" id="outpatient_complaint" style="width:70%;height:70px;"  value=""/><span id="error_outpatient_complaint" style="color:red;"></td>
                    </tr>
                    <tr style="background-color: #F7F7F7">
                        <td>发病天数:</td>
                        <td><input class="easyui-textbox" type="text" name="disease_time" data-options="" style="width:50px;" id="disease_time"/> 天<span id="disease_time" style="color:red;"></span></td>
                    </tr>
                    <tr>
                        <td>现病史:</td>
                        <td><input class="easyui-textbox" type="text" name="current_ill" data-options="multiline:true" style="width:70%;height:70px;" /></td>
                    </tr>
                    <tr >
                        <td>既往病史:</td>
                        <td><input class="easyui-textbox" type="text" name="previous_ill_history" data-options="multiline:true" style="width:70%;height:70px;" /></td>
                    </tr>
                </table>
                 
            </div>
            </div>-->
            &nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="save();">保存</a>


    </form>
</div>
